//
//  OrderDetailFooterView.m
//  JiaoX
//
//  Created by yinqy on 15/1/20.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "OrderDetailFooterView.h"


@implementation OrderDetailFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = CGRectMake(0, 0, JXScreenW, JXPublicInset*3 + LABEL_FONT_SIZE + FREIGHT_FONT_SIZE +49);
        
        UIView *splite1  = [[UIView alloc]init];
        splite1.frame = CGRectMake(JXPublicInset, 0, JXScreenW-JXPublicInset, 0.5);
        [splite1 setBackgroundColor:JXColor(204, 204, 204)];
        [self addSubview:splite1];
        
        _label = [[UILabel alloc]initWithFrame:CGRectMake(JXPublicInset, JXPublicInset, 0, LABEL_FONT_SIZE)];
        [_label setFont:[UIFont systemFontOfSize:LABEL_FONT_SIZE]];
        [_label setTextColor:[UIColor blackColor]];
        [_label setTextAlignment:NSTextAlignmentCenter];
        [self addSubview:_label];
        
        _practcialLable = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_label.frame)+JXPublicInset, JXPublicInset,  0, FREIGHT_FONT_SIZE)];
        [_practcialLable setFont:[UIFont systemFontOfSize:FREIGHT_FONT_SIZE]];
        [_practcialLable setTextColor:JXThemeColor];
        [_practcialLable setTextAlignment:NSTextAlignmentCenter];
        [self addSubview:_practcialLable];
        
        _freightLabel  = [[UILabel alloc]init];
        [_freightLabel setFont:[UIFont systemFontOfSize:FREIGHT_FONT_SIZE]];
        [_freightLabel setFrame:CGRectMake(0, CGRectGetMaxY(self.label.frame)+5, 0, 0)];
        [_freightLabel setTextColor:JXColor(102, 102, 102)];
        [self addSubview:_freightLabel];
    }
    return self;
}

-(void)setTitle:(OrderListItem *)item{
    //总计
    NSString *dprice = [NSString stringWithFormat:@"总计：￥%@",item.orderPrice];
    CGSize dpriceSize =  [dprice sizeWithFont:[UIFont systemFontOfSize:LABEL_FONT_SIZE]];
    //实际支付
    NSString *practcial = [NSString stringWithFormat:@"(实付:￥%d)",item.orderPrice.intValue - item.voucherAmount];
    CGSize practcialSize =  [practcial sizeWithFont:[UIFont systemFontOfSize:FREIGHT_FONT_SIZE]];
    
    [_label setFrame:CGRectMake(self.width/2-(dpriceSize.width/2+practcialSize.width/2), JXPublicInset, dpriceSize.width, dpriceSize.height)];
    [_label setText:dprice];
    
    [_practcialLable setFrame:CGRectMake(CGRectGetMaxX(_label.frame)+5, CGRectGetMaxY(_label.frame)-practcialSize.height, practcialSize.width, practcialSize.height)];
    [_practcialLable setCenterY:_label.centerY];
    [_practcialLable setText:practcial];
    
    //设置运费
    NSString *freight = [NSString stringWithFormat:@"含运费￥%@",item.freight];
    [_freightLabel setText:freight];
    CGSize freightSize = [freight sizeWithFont:[UIFont systemFontOfSize:FREIGHT_FONT_SIZE]];
    [_freightLabel setSize:freightSize];
    _freightLabel.x = self.width/2- _freightLabel.width/2;
}

@end
